package com.eliza.cmps.activity

import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.ScrollView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.eliza.cmps.R


class ScrollViewActivity : AppCompatActivity(), View.OnClickListener {
    lateinit var scrollView: ScrollView


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_scrollview)
        var btn_down = findViewById<Button>(R.id.scrollView_btn_down)
        var btn_up = findViewById<Button>(R.id.scrollView_btn_up)
        btn_down.setOnClickListener(this)
        btn_up.setOnClickListener(this)

        scrollView = findViewById<ScrollView>(R.id.scrollView_sv);

        val sb = StringBuilder()
        for (i in 1..100) {
            sb.append("我是一条文本内容 * $i\n")
        }
        findViewById<TextView>(R.id.txt_show).text = sb.toString()
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.scrollView_btn_down -> scrollView.fullScroll(ScrollView.FOCUS_DOWN)
            R.id.scrollView_btn_up -> scrollView.fullScroll(ScrollView.FOCUS_UP)
        }
    }


}

